package softswitch.agi;


import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;

import org.asteriskjava.fastagi.AgiServerThread;
import org.asteriskjava.fastagi.DefaultAgiServer;
import org.asteriskjava.fastagi.ResourceBundleMappingStrategy;


@Singleton
@Startup
public class AgiLoader {
	
	AgiServerThread ast = new AgiServerThread();
	ResourceBundleMappingStrategy rbms = new ResourceBundleMappingStrategy();
	DefaultAgiServer server =  new DefaultAgiServer();
	
	
	@PostConstruct
	public void initialize() {
	
		System.out.println("Softswitch : Starting Asterisk Agi");
		
	    rbms.setResourceBundleName("softswitch/agi/agimap");	        
        
	    //server.setPort(12345);
        server.setPoolSize(300);
        server.setMaximumPoolSize(300);
        
        server.setMappingStrategy(rbms);
        ast.setAgiServer(server);
        ast.startup();
        
	}
	 
    @PreDestroy
    public void terminate() {
		System.out.println("Softswitch : Shutdown Asterisk Agi");
		ast.shutdown();		
    }
	

}